define(['jquery', 'api', 'user', 'util'], function ($, api, user, util) {
    var vm,
            controller = {
                init: function (id) {
                    if (!user.checkLogin()) return;
                    api.footerShow(0);//隐藏底部导航
                    api.setTitle(L('html_title_user_detail'));
                    api.headerShow(1);
					api.headerTitle(L('html_title_user_detail'));
                    this.render();
                },
                render: function () {
                    var that = this;
                    $('#common').html('<div id="userDetail"></div>');
                    require(['text!pages/user/detail.html', 'Vue'], function (tpl, Vue) {
                        vm = new Vue({
                            el: '#userDetail',
                            data: {
                                show: true,
                                user: user.getData(),
                                loginForm: {
                                    pwd: '',
                                    newpwd: '',
                                    renewpwd: ''
                                },
                                moneyForm: {
                                    pwd: '',
                                    newpwd: '',
                                    renewpwd: ''
                                },
                                showV: 0 //默认值：''登录 支付密码都收起，0展开登录密码，1展开支付密码，
                            },
                            methods: {
                                showPanel: function (index) {
                                    this.showV = index;
                                },
                                changeLogin: function () {
                                    var data = this.loginForm;

                                    if (that.vali(data)) {
                                        var params = {oldloginpwd: data.pwd, newloginpwd: data.newpwd, pwdtype: 49};
                                        api.changePwd(params, function (rtn) {
                                            if (rtn.retcode == '0') {
                                                util.msg('修改成功！');
                                				vm.showPanel('');
                                                vm.resetLoginForm();
                                            } else {
                                                util.dealErrorCode(rtn.retcode);// 20161209dyx:增加提示信息
                                            }
                                        })
                                    }
                                },
                                changeMoney: function () {
                                    var data = this.moneyForm;
                                    var params = {oldloginpwd: data.pwd, newloginpwd: data.newpwd, pwdtype: 50};
                                    if (that.vali(data)) {
                                        api.changePwd(params, function (rtn) {
                                            if (rtn.retcode == '0') {
                                                util.msg('修改成功！');
                                                vm.showPanel('');
                                                vm.resetMoneyForm();
                                            } else {
                                                util.dealErrorCode(rtn.retcode);// 20161209dyx:增加提示信息
                                            }
                                        })
                                    }
                                },
                                resetMoneyForm:function(){
				                	this.moneyForm = {
	                                    pwd: '',
	                                    newpwd: '',
	                                    renewpwd: ''
	                                };
				                },
                                resetLoginForm:function(){
				                	this.loginForm = {
	                                    pwd: '',
	                                    newpwd: '',
	                                    renewpwd: ''
	                                };
				                }
                            },
                            template: tpl
                        })
                    })
                },
                vali: function (data) {
                    var error = false,
                            errorHash = {
                                pwd: '请输入原密码！',
                                newpwd: '请输入新密码！',
                                renewpwd: '请再次确认密码！'
                            };
                    for (var k in errorHash) {
                        if (data[k] == '') {
                            error = errorHash[k];
                            break;
                        }
                    }
                    if (!error && data.pwd == data.newpwd) {
                        error = "新密码不能与原密码相同"
                    }
                    if (!error && data.newpwd !== data.renewpwd) {
                        error = "两次输入密码不一致！"
                    }
                    if (error) {
                        util.msg(error);
                        return false;
                    }
                    return true;
                },
                onRouteChange: function () {
                    vm.show = false;
                }
            };
    return controller;
})